package src.service;

import java.rmi.RemoteException;
import java.util.Set;

import src.domain.MailBox;
import src.domain.OutgoingMessage;
import src.domain.PostOffice;
import src.domain.User;
import src.resource.Md5Resource;
import src.rmi.ImplementationClientService;

public class ClientService {

private static ClientService system=null;
	
	public static ClientService getInstance(){
		if(system==null)
			system=new ClientService();
		return system;
	}
	
	private ClientService(){}
	
	public void saveUser(String name, String userName, String country,
			String city, String address, String phoneNumber, boolean active)
			throws RemoteException {
		new ImplementationClientService().saveUser(name, userName, country, city, address, phoneNumber, active);
		
	}
	
	public void updateUser(User user) throws RemoteException {
		new ImplementationClientService().updateUser(user);
		
	}

	
	public void deleteUser(long idUser) throws RemoteException {
		new ImplementationClientService().deleteUser(idUser);
		
	}
	
	public Set<User> getAllUsers() throws RemoteException {
		return new ImplementationClientService().getAllUsers();
	}
	
	public Set<User> getUsers(String name) throws RemoteException {
		return new ImplementationClientService().getUsers(name);
	}
	

	public void savePostOffice(String name, Set<MailBox> mailBoxes, Set<PostOffice> trustOffices) throws RemoteException {
		new ImplementationClientService().savePostOffice(name,  mailBoxes, trustOffices);
		
	}

	
	public void updatePostOffice(PostOffice postOffice) throws RemoteException {
		new ImplementationClientService().updatePostOffice(postOffice);
		
	}

	
	public void deletePostOffice(long idPostOffice) throws RemoteException {
		new ImplementationClientService().deletePostOffice(idPostOffice);
		
	}

	
	public Set<PostOffice> getAllPostOffices() throws RemoteException {
		return new ImplementationClientService().getAllPostOffices();
	}
	
	public Set<PostOffice> getPostOffices(String name) throws RemoteException {
		return new ImplementationClientService().getPostOffices(name);
	}
	
	public Set<PostOffice> getAvailablePostOffices(final PostOffice postOffice)throws RemoteException {
		return new ImplementationClientService().getAvailablePostOffices(postOffice);
	}
	
	public  void saveMailBox(String name, String pass, boolean active, User user,Set<PostOffice> postOffices) throws RemoteException{
		
		new ImplementationClientService().saveMailBox(name, Md5Resource.encriptarmd5(pass), active, user,postOffices);
		
	}
	
	
	public void updateMailBox(MailBox mailBox) throws RemoteException{
		new ImplementationClientService().updateMailBox(mailBox);
	}
	
	
	public void deleteMailBox(long idMailBox) throws RemoteException{
		new ImplementationClientService().deleteMailBox(idMailBox);
	}
	
	
	public Set<MailBox> getAllMailBoxes() throws RemoteException{
		return new ImplementationClientService().getAllMailBoxes();
	}
	
	public Set<PostOffice> getUnassignedPostOffices(Long idMailBox) throws RemoteException{
		return new ImplementationClientService().getUnassignedPostOffices(idMailBox);
	}
	
	public Set<MailBox> getMailBoxes(String nameMailBox) throws RemoteException{
		return new ImplementationClientService().getMailBoxes(nameMailBox);
	}
	
	public MailBox getMailBoxByName(String nameMailBox)throws RemoteException{
		return new ImplementationClientService().getMailBoxByName(nameMailBox);
	}
	
	public User getUserByUserName(String userName)throws RemoteException{
		return new ImplementationClientService().getUserByUserName(userName);
	}
	
	public PostOffice getPostOfficeByName(String postOfficeName)throws RemoteException{
		return new ImplementationClientService().getPostOfficeByName(postOfficeName);
	}
	
	public Set<MailBox> getMailBoxesByPostOffice(long idPostOffice)throws RemoteException{
		return new ImplementationClientService().getMailBoxesByPostOffice(idPostOffice);
	}
	
	public Set<OutgoingMessage> getOutgoingMessagesByMailBox(long idMailBox)throws RemoteException{
		return new ImplementationClientService().getOutgoingMessagesByMailBox(idMailBox);
	}
	
	public Set<MailBox> getMailBoxesByUser(long idUser)throws RemoteException{
		return new ImplementationClientService().getMailBoxesByUser(idUser);
	}
}
